package com.hzdp.coc;

public class WaitThread {

	public static void main(String[] args) {
		Service service = new Service();
		new Thread(new TestThread("a", service)).start();
		new Thread(new TestThread("b", service)).start();
	}
}

class TestThread implements Runnable {

	private String name;
	private Service service;

	public TestThread(String name, Service service) {
		this.name = name;
		this.service = service;
	}

	@Override
	public void run() {
		service.display(name);
	}

}

class Service {
	public synchronized void display(String name) {
		System.out.println(name + 1);
		if (name.equals("b")) {
			try {
				wait(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println(name + 2);
	}
}
